// ****************************************************************************
//	Copyright (c) 2011 Daniel Watman
//	http://www.keycommander.net/
// ****************************************************************************
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//	
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//	
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
// ****************************************************************************
//	File: USB_enum.h
//	Purpose: USB descriptors
//	Author:	Daniel Watman
//	Created: 2011.02.28
//	Updated: 2011.02.28
//	Version: 0.1
// ****************************************************************************
//	Comments:
//		* The basic descriptors are based on Maxim application note AN3690 
// ****************************************************************************

#include "types.h"

#define USB_NUM_STRINGS	4

const u08 USB_DD[] = {	// DEVICE descriptor
	18,	       		// blength
	0x01,			// DescriptorType = Device (1)
	0x00,0x01,		// bcdUSB(L/H) USB spec rev (BCD)
	0x00,0x00,0x00, // bDeviceClass, bDeviceSubClass, bDeviceProtocol
	0x40,			// bMaxPacketSize0 EP0 is 64 bytes
	0x6A,0x0B,		// idVendor(L/H)--Maxim is 0B6A
	0x46,0x53,		// idProduct(L/H)--5346
	0x34,0x12,		// bcdDevice--1234
	1,2,3,			// Manufacturer, Product, SerialNumber
	1				// bNumConfigurations
};

const u08 USB_CD[] = {	// CONFIGURATION descriptor
	0x09,			// bLength
	0x02,			// bDescriptorType = Config
	41,0x00,		// wTotalLength(L/H) = 41 bytes
	0x01,			// bNumInterfaces
	0x01,			// bConfigValue
	0x00,			// iConfiguration
	0x80,			// bmAttributes. b7=1 b6=self-powered b5=RWU supported
	0xFA,			// MaxPower is 500 ma
// INTERFACE Descriptor at [9]
	9,				// blength = 9
	0x04,			// bDescriptorType = Interface Descriptor
	0x00,			// bInterfaceNumber
	0x00,			// bAlternate Setting
	0x02,			// bNum Endpoints
	0x03,			// bInterfaceClass = HID
	0x00,0x00,		// bInterfaceSubClass, bInterfaceProtocol
	0x00,			// iInterface
// HID Descriptor at [18]
	0x09,			// bLength
	0x21,			// bDescriptorType = HID
	0x10,0x01,		// bcdHID(L/H) Rev 1.1
	0x00,			// bCountryCode (none)
	0x01,			// bNumDescriptors (one report descriptor)
	0x22,			// bDescriptorType	(report)
	62,0,			// CD[25]: wDescriptorLength(L/H) (report descriptor size is 62 bytes)
// Endpoint Descriptor for EP3IN at [27]
	0x07,			// bLength
	0x05,			// bDescriptorType (Endpoint)
	0x83,			// bEndpointAddress (EP3-IN)		
	0x03,			// bmAttributes	(interrupt)
	64,0,           // wMaxPacketSize (64)
	10,				// bInterval (poll every 10 msec)
// Endpoint Descriptor for EP1OUT at [34]
	0x07,			// bLength
	0x05,			// bDescriptorType (Endpoint)
	0x01,			// bEndpointAddress (EP1-OUT)		
	0x03,			// bmAttributes	(interrupt)
	64,0,           // wMaxPacketSize (64)
	10				// bInterval (poll every 10 msec)
};

const u08 USB_SD[USB_NUM_STRINGS][64] = {	// STRING descriptors
	// string descriptor 0 - language
	{
		0x04,			// bLength
		0x03,			// bDescriptorType = string
		0x09,0x04		// wLANGID(L/H) = English-United Sates
	},

	// string descriptor 1 - manufacturer ID
	{
	12,				// bLength
	0x03,			// bDescriptorType = string
	'M',0,
	'a',0,
	'x',0,
	'i',0,
	'm',0 // text in Unicode
	},

	// string descriptor 2 - product ID
	{
		26,			// bLength
		0x03,			// bDescriptorType = string
		'K',0,
		'e',0,
		'y',0,
		'C',0,
		'o',0,
		'm',0,
		'm',0,
		'a',0,
		'n',0,
		'd',0,
		'e',0,
		'r',0
	},

	// string descriptor 3 - serial number
	{
		20,			// bLength
		0x03,			// bDescriptorType = string
		'S',0,				
		'/',0,
		'N',0,
		' ',0,
		'0',0,
		'0',0,
		'0',0,
		'0',0,
		'0',0
	}
};

const u08 USB_RD[] = {	// REPORT descriptor (length 62)
	0x05,0x01,		// Usage Page (generic desktop)
	0x09,0x06,		// Usage (keyboard)
	0x15,0x00,		// Logical Minimum = 0,
	0xA1,0x01,		// Collection (Application)
	0x05,0x07,		//   Usage Page 7 (keyboard/keypad)
	0xA1,0x01,		//   Collection (Application)
	0x19,0xE0,		//     Usage Minimum = 224 (left control)
	0x29,0xE7,		//     Usage Maximum = 231 (right GUI)
	0x25,0x01,		//     Logical Maximum = 1
	0x75,0x01,		//     Report Size = 1
	0x95,0x08,		//     Report Count = 8
	0x81,0x02,		//    Input(Data,Variable,Absolute)
	0x95,0x01,		//     Report Count = 1
	0x75,0x08,		//     Report Size = 8
	0x81,0x03,		//    Input(Constant,Variable,Absolute)
	0x95,0x06,		//     Report Count = 6
	0x75,0x08,		//     Report Size = 8
	0x25,0x65,		//     Logical Maximum = 101
	0x19,0x00,		//     Usage Minimum = 0
	0x29,0x65,		//     Usage Maximum = 101
	0x81,0x00,		//    Input(Data,Array,Absolute)
	0xC0,			//   End Collection
	0x05,0x14,		//   Usage Page (Alphanumeric display)
	0x09,0x01,		//   Usage (Alphanumeric display)
	0xA1,0x01,		//   Collection (Application)
	0x09,0x2C,		//     Usage (Display data)
	0x26,0xFF,0x00,	//     Logical Maximum = 255
	0x75,0x08,		//     Report Size = 8
	0x95,0x08,		//     Report Count = 8***//64
	0x91,0x02,		//    Output(Data,Variable,Absolute)
	0xC0,			//   End Collection
	0xC0			// End Collection
};
